package leetcode_2501_2600;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class LeeCode_2564 {
    public static void main(String[] args) {
//        System.out.println(Arrays.deepToString(substringXorQueries("101101", new int[][]{{0, 5}, {1, 2}})));
//        System.out.println(Arrays.deepToString(substringXorQueries("0101", new int[][]{{12, 8}})));
        System.out.println(Arrays.deepToString(substringXorQueries("1", new int[][]{{4, 5}})));
    }
    private static int[][] substringXorQueries(String s, int[][] queries) {
        int n = queries.length;
        int[][] ans = new int[n][2];
        Map<String, Integer> map = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            int t = 1;
            while (t <= 32 && i + t <= s.length()){
                String son = s.substring(i, i + t);
                if (!map.containsKey(son)){
                    map.put(son, i);
                }
                t++;
            }
        }
        for (int i = 0; i < n; i++) {
            String str = Integer.toBinaryString(queries[i][0] ^ queries[i][1]);
            if (map.containsKey(str)){
                int start = map.get(str);
                ans[i][0] = start;
                ans[i][1] = start + str.length() - 1;
            }else {
                ans[i][0] = -1;
                ans[i][1] = -1;
            }
        }
        return ans;
    }
}
